package com.zl.tby.vo;

import com.zl.tby.model.TbyLayerConfig;
import lombok.Data;
import org.noear.solon.validation.annotation.Length;
import org.noear.solon.validation.annotation.NotBlank;

import java.time.format.DateTimeFormatter;

/**
 * 地图图层配置
 * @author changpeng
 * @version 1.0
 * @since 2024/9/24 20:13
 */
@Data
public class TbyLayerConfigForm {
    /**主键id*/
    private Long id;
    /**图层名称*/
    @NotBlank(message = "图层名称不能为空")
    @Length(max = 20, message = "图层名称最大长度为20")
    private String name;
    /**预览图片*/
    @NotBlank(message = "预览图片不能为空")
    private String icon;
    /**图层地址*/
    @NotBlank(message = "图层地址不能为空")
    @Length(max = 64, message = "图层地址最大长度为64")
    private String url;
    /**是否启用 1：启用*/
    private Integer active;
    private String createTimeFormat;

    public TbyLayerConfig createEntity() {
        TbyLayerConfig entity = new TbyLayerConfig();
        entity.setName(this.getName());
        entity.setUrl(this.getUrl());
        entity.setIcon(this.getIcon());
        entity.setActive(this.getActive());
        return entity;
    }

    public void updateEntity(TbyLayerConfig entity) {
        entity.setName(this.getName());
        entity.setUrl(this.getUrl());
        entity.setIcon(this.getIcon());
        entity.setActive(this.getActive());
    }

    public static TbyLayerConfigForm convert(TbyLayerConfig entity) {
        TbyLayerConfigForm form = new TbyLayerConfigForm();
        form.setId(entity.getId());
        form.setName(entity.getName());
        form.setUrl(entity.getUrl());
        form.setIcon(entity.getIcon());
        form.setActive(entity.getActive());
        form.setCreateTimeFormat(entity.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
        return form;
    }
}
